﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Snom.Tests.Properties;
using System.IO;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Xml;
using System.Collections.Specialized;
using System.Drawing;

namespace Snom.Tests
{
    [TestClass]
    public class CommandsSerderTests
    {
        [TestMethod]
        public void ProxyWithCredentials()
        {
            CommandsSender commandsSender = new CommandsSender(Settings.Default.MyPhoneIpAddress, Settings.Default.MyPhoneUsername, Settings.Default.MyPhonePassword, string.IsNullOrEmpty(Settings.Default.MyProxyUrl)? null : new Uri(Settings.Default.MyProxyUrl));
            //commandsSender.ChangeSetting("action_dnd_on_url", string.Empty);
            commandsSender.ChangeSetting(SnomSettingKeys.ActionDndOnUrl, "sdcs1");
        }

        [TestMethod]
        public void CreateSettings()
        {
            string line = null;
            using (StreamReader reader = new StreamReader(@"..\..\..\Snom\HttpSamples\Settings.cfg"))
            {
                while ((line = reader.ReadLine()) != null)
                {

                    Debug.WriteLine(line);
                }
            }
        }

        [TestMethod]
        public void CreateSettingsFromXml()
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(@"..\..\..\Snom\HttpSamples\Settings.xml");
            XmlNode settingsRootNode = xml.DocumentElement.FirstChild;
            foreach (XmlNode settingNode in settingsRootNode.ChildNodes)
            {
                string name = settingNode.Name;
                XmlAttribute idxAttribute = settingNode.Attributes["idx"];
                if (idxAttribute != null)
                {
                    name += idxAttribute.Value;
                }

                string[] parts = name.Split('_');
                for (int i = 0; i < parts.Length; i++)
                {
                    parts[i] = char.ToUpper(parts[i][0]) + parts[i].Substring(1);
                }
                string varName = string.Join(string.Empty, parts);
                Debug.WriteLine("public const string " + varName + " = \"" + name + "\";");
            }
        }

        

        [TestMethod]
        public void GetScreenDisplayImage()
        {
            CommandsSender commandsSender = new CommandsSender(Settings.Default.MyPhoneIpAddress, Settings.Default.MyPhoneUsername, Settings.Default.MyPhonePassword, string.IsNullOrEmpty(Settings.Default.MyProxyUrl) ? null : new Uri(Settings.Default.MyProxyUrl));
            using (Image image = commandsSender.GetScreenDisplayImage())
            {
                image.Save("screen.bmp");
            }
            Process p = new Process();
            p.StartInfo.FileName = "screen.bmp";
            p.Start();
        }
    }
}
